import GChild from "../../../Core/GView/GChild";
import { ITEM_TYPE, PART_ITEM } from "../../Common/Define";
import { Res } from "../../Common/UIResources";
import GameMgr from "../../Logic/GameMgr";

const { ccclass, property, menu, executeInEditMode } = cc._decorator;
@ccclass @menu('View/Home/ItemSignIn')

export default class ItemSignIn extends GChild {

    @property(cc.Node) Select: cc.Node = null;
    @property(cc.Sprite) icon: cc.Sprite = null;
    @property(cc.Node) signBtn: cc.Node = null;
    @property(cc.Label) reward: cc.Label = null;

    protected siginIndata: SSignInDataRaw = null;
    init() {

    }

    initTextureWithData(array: SSignInDataRaw, isRoleStand: boolean = false, isBoldName: boolean = false) {
        this.siginIndata = array;
        let arr = this.siginIndata.award[0];
        let id = null;
        let num = null;
        this.assetImpl.spriteAtlasFrame(this.icon, Res.texture.views.icon, 'icon_100');

        switch (arr[PART_ITEM.TYPE]) {
            case ITEM_TYPE.HERO:
                {
                    let hero: SHeroDataRaw = GameMgr.heroData.getRaw(arr[PART_ITEM.ID]);
                    this.reward.string = hero.name + '';
                    this.assetImpl.spriteFrame(this.icon, Res.texture.hero.hero + this.siginIndata.icon);
                    this.icon.node.setScale(0.2);
                    this.node.getChildByName('str').active = true;
                    this.node.getChildByName('str').scale = 1.2;
                    break;
                }
            case ITEM_TYPE.PROP:
                {

                    break;
                }
            case ITEM_TYPE.EQUIPDATA:
                {
                    let equip: SEquipDataRaw = GameMgr.equipData.getRaw(arr[PART_ITEM.ID]);
                    this.reward.string = equip.name + '';
                    this.assetImpl.spriteAtlasFrame(this.icon, Res.texture.views.icon, 'icon_' + equip.icon);
                    break;
                }
            case ITEM_TYPE.CURRENCY:
                {
                    this.assetImpl.spriteAtlasFrame(this.icon, Res.texture.views.icon, 'icon_' + this.siginIndata.icon);
                    this.reward.string = arr[PART_ITEM.NUM] + '';
                    break;
                }
            default:
                break;
        }


        // this.assetImpl.spriteFrame(this.heroImg, Res.texture.hero.hero + this._sHeroData.icon);
        // this.assetImpl.spriteAtlasFrame(this.bg, Res.texture.views.common, "quality_" + this.data.quality)
    }

    /**展示已签到表现 */
    public haveSigned() {
        this.signBtn.getComponent(cc.Button).enableAutoGrayEffect = true;
        this.signBtn.getComponent(cc.Button).interactable = false;
        if (this.signBtn.getComponent(cc.Button).interactable) {
            this.Select.active = true;
        } else {
            this.signBtn.children[0].active = true;
            this.Select.active = false;
        }
    }

    /**隐藏未签到表现 */
    public hideSigned() {
        this.Select.active = false;
        this.signBtn.getComponent(cc.Button).enableAutoGrayEffect = false;
        this.signBtn.getComponent(cc.Button).interactable = false;
    }

    public recoverySigned() {
        this.Select.active = true;
        this.signBtn.getComponent(cc.Button).interactable = true;
    }

    /**是否展示今日已签到边框 */
    public showTodayToday(isShow: boolean) {

    }
}       